﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RentIt06WPFClient
{
    using RentIt06WPFClient.AdminSession;

    /// <summary>
    /// Interaction logic for ListUsers.xaml
    /// </summary>
    public partial class ListUsers : Page
    {
        public ListUsers()
        {
            InitializeComponent();
        }

        private void loadPage(object sender, RoutedEventArgs e)
        {
            var list = Session.Admin.ReadAllAccounts();
            userList.ItemsSource = list;
        }

        private void ListBoxItem_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            var s = (ListBoxItem)sender;
            this.ListBoxItem_Clicked(s);
        }

        private void editButton_Click(object sender, RoutedEventArgs e)
        {
            if (userList.SelectedItem == null) return;
            NavigationService.Navigate(new ManageUser((AdminSession.Account)userList.SelectedItem));
        }

        private void ListBoxItem_Clicked(ListBoxItem item)
        {
            NavigationService.Navigate(new ManageUser((AdminSession.Account)item.DataContext));
        }
    }
}
